import os
from concurrent.futures import ProcessPoolExecutor


def create_file(file_name):
    content = '一般情况下，主进程会等待子进程全部结束后，才会结束。但是，很多时候，当主进程结束后，子进程会立即结束，' \
              '比如：关闭浏览器（Google)，打开的网页会直接结束这个时候需要将守护主进程daemon设置为True'
    for i in range(50):
        file_root = r'D:\Users\asus-pc\Desktop\a'
        if not os.path.exists(file_root):
            os.mkdir(file_root)
        file_path_finally = file_root + os.sep + str(file_name) + str(i) + '.txt'
        print(file_path_finally)
        if not os.path.exists(file_path_finally):
            with open(file_path_finally, 'w', encoding='utf8') as f:
                f.write(content)
        else:
            print('文件已存在')


if __name__ == '__main__':
    file_list = [x for x in range(10)]
    with ProcessPoolExecutor() as pool:
        pool.map(create_file, file_list)
